$(function(){
	JobsSearch();
	$(".form_datetime").datetimepicker({
		format: 'yyyy-mm-dd hh:ii',
		language:  'zh-CN',
        weekStart: 0,
        todayBtn:  'linked',
        autoclose: 1,
        startView: 2,
//        minView: 1,
        forceParse: 0,
        startDate:new Date()
	});
	
    $('.needs-item').mouseover(function(){
        $(this).addClass('shadowClass');
    });
    $('.needs-item').mouseout(function(){
        $(this).removeClass('shadowClass');
    });

    /**
     * 查看用户简历
     */
    $(document).on('click','.viewResume',function(){
        var authuser = $('#authuser').val();
        if(authuser) {
//            jQuery.noConflict();

            var resume_id = $(this).attr('data-resume_id');
            var user_id = $(this).attr('data-user_id');
            var need_id = $(this).attr('data-need_id');
            var url = $(this).attr('data-url') + '?uid=' + user_id + '&id=' + resume_id +'&nid=' + need_id;
            var show = $(this).attr('data-value');
            $.ajax({
                'url': url,
                'type': 'GET',
                error: function (data) {
                    layer.open({title: '系统提示', content: '简历已删除！'});
                },
                success: function (response) {
                    if (response.code == 0) {
                        var result = response.data;
                        var html = '';
                        var experiences = '';
                        var educationals = '';
                        var projects = '';

                        $.each(result.experiences, function (key, exp) {
                            experiences += ' <div class="resume-content mr_w840" id="experience">'
                                + '     <div class="list_show" id="list_show_experience" >'
                                + '         <div class="mr_jobe_list">'
                                + '             <div class="clearfix">'
                                + '                 <div class="mr_content_l">'
                                + ' 					<div class="l2">'
                                + ' 						<a class="projectTitle nourl">' + exp.company_name + '</a>'
                                + ' 						<p>' + exp.job + '</p>'
                                + ' 					</div>'
                                + ' 				</div>'
                                + ' 				<div class="mr_content_r">'
                                + ' 					<span>' + exp.start_at + ' - ' + exp.end_at + '</span>'
                                + ' 				</div>'
                                + '             </div>'
                                + '             <div class="mr_content_m">'
                                + exp.content
                                + ' 			</div>'
                                + '         </div>'
                                + '     </div>'
                                + ' </div>';
                        });
                        $.each(result.educationals, function (ke, edu) {
                            educationals += ' <div class="resume-content mr_w840">'
                                + '     <div class="list_show" id="list_show_educational" >'
                                + '         <div class="mr_jobe_list">'
                                + '             <div class="clearfix">'
                                + '                 <div class="mr_content_l">'
                                + ' 					<div class="l2">'
                                + ' 						<a class="projectTitle nourl">' + edu.school + '</a>'
                                + ' 						<p>' + result.degrees[edu.degree] + '· ' + edu.major + '</p>'
                                + ' 					</div>'
                                + ' 				</div>'
                                + ' 				<div class="mr_content_r">'
                                + ' 					<span>' + edu.graduated_at + '年毕业</span>'
                                + '  				</div>'
                                + '             </div>'
                                + '         </div>'
                                + '     </div>'
                                + ' </div>';
                        });
                        $.each(result.projects, function (k, prj) {
                            projects += '<div class="mr_jobe_list">'
                                + '              <div class="clearfix">'
                                + '                 <div class="mr_content_l">'
                                + ' 					<div class="l2">'
                                + ' 						<a class="projectTitle nourl">' + prj.name + '</a>'
                                + ' 						<p>' + prj.duty + '</p>'
                                + ' 					</div>'
                                + ' 				</div>'
                                + ' 				<div class="mr_content_r">'
                                + ' 					<span>' + prj.start_at + ' - ' + prj.end_at + '</span>'
                                + ' 				</div>'
                                + '             </div>'
                                + ' 			<div class="mr_content_m">'
                                + prj.intro
                                + ' 			</div>'
                                + '         </div>';
                        })
                        var signature = '';
                        if (result.signature != null && result.signature != undefined)
                            signature = result.signature;
                        var shenfen = '';
                        if(result.shenfen != null && result.shenfen != undefined && result.shenfen != '') {
                        	shenfen = '		<div class="mb-10">'
                            +'			<span  class="userinfo-show">'
                            +'    		<img src="/images/front/member/home.jpg">'
                            +'    		<span class="ml-10">'+result.shenfen+'</span>'
                            +'			</span>'
                            +'		</div>';
                        	
                        }
                        var basicinfo = '';
                        if(show == 'show') {
                        	basicinfo =  + '             <span  class="userinfo-show">'
			                            + '                 <img src="/images/front/member/call.jpg">'
			                            + '                 <span class="ml10">'
			                            + '                     ' + result.phone + '&nbsp;&nbsp;&nbsp;&nbsp;'
			                            + '                     <i class="icon-envelope"></i>&nbsp;' + result.email
			                            + '                 </span>'
			                            + '             </span>';
                        } 
                        
                        html = '<div class="resume-header">'
                            + '   	<img src="/images/front/member/bg.jpg">'
                            + '       <div class="resume-header-logo">'
                            + '           <img src="' + result.logo + '">'
                            + '     </div>'
                            + ' </div>'
                            +  ' <div class="resume-userinfo">'
                            + '     <div class="resume-userinfo-title mr_w840 mb15">'
                            + '         <span  class="userinfo-show user-name">' + result.user.real_name + '</span>'
                            + '     </div>'
                            + '     <div class="resume-userinfo-center mr_w840 mb15">'
                            + '         <span  class="userinfo-show">' + signature + '</span>'
                            + '     </div>'
                            + '     <div class="resume-userinfo-center mr_w840">'
                            + shenfen
                            + '          <div class="mb10">'
                            + '             <span  class="userinfo-show">'
                            + '                 <img src="/images/front/member/data.jpg">'
                            + '                 <span class="ml10">'
                            + '                     ' + result.sex + '&nbsp;&nbsp;'
                            + '                     ' + result.age + '岁&nbsp;&nbsp;'
                            + '                     ' + result.degrees[result.highest_degree] + '&nbsp;&nbsp;'
                            + 						result.gznxs[result.gznx] +'&nbsp;工作经验'
                            + '                 </span>'
                            + '             </span>'
                            + '         </div>'
                            + '         <div class="mb10">'
                            + basicinfo
                            + '         </div>'
                            + '     </div>'
                            + ' </div>'
                            + ' <div class="mr_moudle_head clearfix mr_w840">'
                            + ' 	<div class="fl">'
                            + ' 		<div class="mr_title">'
                            + ' 			<span class="mr_title_l"></span><span class="mr_title_c">工作经历</span><span class="mr_title_r" style="width: 342px"></span>'
                            + ' 		</div>'
                            + ' 	</div>'
                            + ' </div>'
                            + experiences
                            + ' <div class="mr_moudle_head clearfix mr_w840">'
                            + ' 	<div class="fl">'
                            + ' 		<div class="mr_title">'
                            + ' 			<span class="mr_title_l"></span><span class="mr_title_c">教育经历</span><span class="mr_title_r" style="width: 342px"></span>'
                            + ' 		</div>'
                            + ' 	</div>'
                            + ' </div>'
                            + educationals
                            + ' <div class="mr_moudle_head clearfix mr_w840">'
                            + ' 	<div class="fl">'
                            + ' 		<div class="mr_title">'
                            + ' 			<span class="mr_title_l"></span><span class="mr_title_c">项目经验</span><span class="mr_title_r" style="width: 342px"></span>'
                            + ' 		</div>'
                            + ' 	</div>'
                            + ' </div>'
                            + ' <div class="resume-content mr_w840">'
                            + '     <div class="list_show" id="list_show_projects" >'
                            + projects
                            + '     </div>'
                            + ' </div>'
                            + ' <div class="mr_moudle_head clearfix mr_w840">'
                            + ' 	<div class="fl">'
                            + ' 		<div class="mr_title">'
                            + ' 			<span class="mr_title_l"></span><span class="mr_title_c">自我描述</span><span class="mr_title_r" style="width: 342px"></span>'
                            + ' 		</div>'
                            + ' 	</div>'
                            + ' </div>'
                            + ' <div class="resume-content mr_w840">'
                            + '    <div class="self_intro clearfix" id="intro_show">';

                        if (result.intro != undefined && result.intro != null) {
                            html += ' <div class="fl self-intro-right" id="other_insert">'
                                + result.intro
                                + '         </div>';
                        }
                        html += '     </div>'
                            + ' </div>'
                            + ' <div class="mr_moudle_head clearfix mr_w840">'
                            + ' 	<div class="fl">'
                            + ' 		<div class="mr_title">'
                            + ' 			<span class="mr_title_l"></span><span class="mr_title_c">期望工作</span><span class="mr_title_r" style="width: 342px"></span>'
                            + ' 		</div>'
                            + ' 	</div>'
                            + ' </div>';
                        if (result.needs != undefined && result.needs != null) {
                            html += ' <div class="resume-content mr_w840">'
                                + '     <div class="list_show" >'
                                + '         <div class="mr_jobe_list clearfix" id="expect_show">'
                                + '         	<ul>'
                                + '         	   <li><i class="icon-user-md"></i>&nbsp;&nbsp;' + result.needs.name + '</li>'
                                + '         	   <li><i class="icon-time"></i>&nbsp;&nbsp;' + result.gzxzs[result.needs.job_type] + '</li>'
                                + '         	   <li><i class="icon-map-marker"></i>&nbsp;&nbsp;' + result.needs.cityname + '</li>'
                                + '         	   <li><i class="icon-money"></i>&nbsp;&nbsp;' + result.salarys[result.needs.expect_wages] + '</li>'
                                + '         	</ul>'
                                + '     	</div>'
                                + ' 	</div>'
                                + '</div>';
                        }
                        if ((result.skill_exam_score != undefined && result.skill_exam_score != null)) {

                            html += ' <div class="mr_moudle_head clearfix mr_w840">'
                                + ' 	<div class="fl">'
                                + ' 		<div class="mr_title">'
                                + ' 			<span class="mr_title_l"></span><span class="mr_title_c">考试成绩</span><span class="mr_title_r" style="width: 342px"></span>'
                                + ' 		</div>'
                                + ' 	</div>'
                                + ' </div>';
                            html += ' <div class="resume-content mr_w840">'
                                + '     <div class="list_show" >'
                                + '         <div class="mr_jobe_list clearfix" id="expect_show">'
                                + '         	<ul>';
                            if (result.skill_exam_score != undefined && result.skill_exam_score != null) {
                                html +='         	   <li class="view_history" style="cursor:pointer;" data-id="'+result.needs.skill_exam+'" data-uid="'+user_id+'">技能测试成绩：&nbsp;&nbsp;' + result.skill_exam_score + '</li>';
                                if(result.needs.character_exam == "MBTI"){
                                    html += '         	   <li class="view_history" style="" >性格测试结果：&nbsp;&nbsp;' + '</li>';
                                }else {
                                    html += '         	   <li class="view_history" style="" >性格测试结果：&nbsp;&nbsp;' + result.needs.character_exam + '</li>';
                                }
                            }

                            html += '         	</ul>'
                                + '     	</div>'
                                + ' 	</div>'
                                + '</div>';
                        }
                        if (result.resume_status != undefined && result.resume_status != null) {
                            html += '<div class="mr_self_state company-center-form">'
                                + '	<div class="form_wrap">'
                                + '    <input id="resume_status" name="resume_status" type="button" style="height: 44px;" class="form-control"  value="' + result.resume_status + '">'
                                + '	</div>					'
                                + '</div>';
                        }
                        $('#resumeModalLabel').html(result.user.real_name + '的简历');
                        $('#resumebody').html(html)
                        $('.send_inteview').attr('data-resume_id',result.id)
                        $('.send_inteview').attr('data-needId',need_id);
                        $('.send_inteview').attr('data-disable',result.has_notice)
                        if(result.has_notice){
                            $('.send_inteview').html('已经通知面试')
                            $('.send_inteview').removeClass('btn-primary');
                            $('.send_inteview').addClass('btn-primary-none');
                        }else{
                            $('.send_inteview').html('通知面试');
                            $('.send_inteview').removeClass('btn-primary-none');
                            $('.send_inteview').addClass('btn-primary');
                        }

                        $('#resumeModal').modal();

                    } else {
                        layer.open({title: '系统提示', content: response.message});
                    }
                }
            });
        }else{
            layer.open({title:'系统提示',content:'尚未登录，请登录'});
        }

    })

    $('.send_inteview').click(function() {

        var resume_id = $(this).attr('data-resume_id');
        var has_notice = $(this).attr('data-disable');
        var needId = $(this).attr('data-needId');
        if(has_notice==1){
            return true;
        }
        var $authuser = $('#authuser').val();
        if ($authuser) {
            var $test_html = '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-top: -12px;">';
            $test_html += '<span aria-hidden="true">&times;</span></button></div>';
            $test_html += '<div class="modal-body" style="text-align: center"> <div id="isTestbody">';
            $test_html += '<span>是否添加企业测试</span>';
            $test_html += '</div></div>';

            $test_html += '<div class="modal-footer">';
            $test_html += '<button type="button" class="btn btn-primary addtest fl" data-dismiss="modal" data-need="'+needId+'"  data-resume="'+resume_id+'">添加测试</button>';
            $test_html += '<button type="button" class="btn btn-primary notest" data-dismiss="modal" data-need="'+needId+'" data-resume="'+resume_id+'">无需测试</button></div>';
            $('.invite').html($test_html);
            $('#inviteModal').modal();


        } else {
            layer.open({title: '系统提示', content: '尚未登录，请登录'});
        }
    });
    
    $(document).on('click','.addtest',function(){
    	var resume_id = $(this).attr('data-resume');
    	var needId = $(this).attr('data-need');
        $.ajax({
            'url':'/biz/talent/testlist',
            'type':'GET',
            error:function(data){
                layer.open({title:'系统提示',content:'网络异常！'});
            },
            success: function (response) {
                    var result = response.data;

                    var examlist_html =    '<select name="examlist" id="examlist" onchange="seltime('+resume_id+','+needId+',this.value)">';
                    	examlist_html += '<option value="0">选择试卷</option>';
                    if (response.total) {
                        $.each(result,function(key,exp){
                        	examlist_html += ' <option value="'+exp.id+'">'+exp.name+'</option>';
                        })
                        examlist_html += '</select>';
                    }else {
                    	examlist_html += '</select>';
                    	examlist_html += '<div class="no_exam">还没有组卷，<a href="/biz/exam" >点击这里</a></div>';
                    }

                    $('#examSelect').html(examlist_html)
                    $('#examModal').modal();
                }
        });
    });
    
    $(document).on('click','.notest',function(){
    	var resume_id = $(this).attr('data-resume');
    	var needId = $(this).attr('data-need');
    	seltime(resume_id,needId,0);
    });

    $(document).on('click','.submit_invited',function(){
    	var form = $('#check_interview_time');
    	var data = form.serializeArray();
    	var params = {
    			url: '/biz/talent/sendinvite',
    			type: 'POST',
    			dataType: 'json',
    			data: data,
    	};
		$.ajax(params).done(function(resp){
			if(resp.status == 'success') {
				form.get(0).reset();
				layer.open({title:'系统提示',content:resp.msg});
			}else{
				layer.open({title:'系统提示',content:resp.msg});
			}
    	}).fail(function(erro){
    		layer.open({title:'系统提示',content:'网络异常...'});
    	});
    })
});

function seltime(resume_id,need_id,exam_id){
	
	var form = $("#check_interview_time");
	form.find('input[name=rid]').val(resume_id);
	form.find('input[name=eid]').val(exam_id);
	form.find('input[name=nid]').val(need_id);

    $('#examModal').modal('hide');
    $('#selTimeModal').modal()
}

function JobsSearch (){

    $("#needs-lists-keyword").keydown(function(e){
        var e = e || event,
            keycode = e.which || e.keyCode || e.charCode;
        if (keycode==13) {
            var kw = $("#needs-lists-keyword").val(),areaid = $("#jobs-lists-area").val(),industry = $("#jobs-lists-industry").val(),salary = $("#jobs-lists-salary").val(),gznx = $("#jobs-lists-gznx").val(),degree = $("#jobs-lists-degree").val(),sort = $("#jobs-lists-sort").val();
            var url = "/biz/talent/lists?kw="+kw+"&areaid="+areaid+"&industry="+industry+"&salary="+salary+"&gznx="+gznx+"&degree="+degree+"&sort="+sort;
            window.location.href = url;
            return false;
        }
    });

    $("#needs-lists-searchbtn").click(function(){
        var kw = $("#needs-lists-keyword").val(),areaid = $("#jobs-lists-area").val(),industry = $("#jobs-lists-industry").val(),salary = $("#jobs-lists-salary").val(),gznx = $("#jobs-lists-gznx").val(),degree = $("#jobs-lists-degree").val(),sort = $("#jobs-lists-sort").val();
        var url = "/biz/talent/lists?kw="+kw+"&areaid="+areaid+"&industry="+industry+"&salary="+salary+"&gznx="+gznx+"&degree="+degree+"&sort="+sort;
        window.location.href = url;
        return false;
    });

}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes();
    return currentdate;
}

